﻿using System;
using System.Collections.Generic;
using System.IO;

namespace OpenLS.Spreadsheet.Formats.Biff.Records
{
    internal class DBQueryExtRecord : BiffRecord
    {
        private FrtHeaderOld frtHeaderOld;
        private DataSourceType dbt;
        private ConnGrbitDbt grbitDbt;
        private byte bVerDbqueryEdit;
        private byte bVerDbqueryRefreshed;
        private byte bVerDbqueryRefreshableMin;
        private ushort coledb;
        private ushort cstFuture;
        private ushort wRefreshInterval;
        private ushort wHtmlFmt;
        private ushort cwParamFlags;
        private List<PBT> rgPbt;
        private byte[] rgbFutureBytes;

        protected override void ReadContent(BiffReaderContext context, int length)
        {
            this.frtHeaderOld = new FrtHeaderOld(context.Reader);
            this.dbt = (DataSourceType) context.ReadUInt16();
            var ag = context.ReadUInt16();
            this.grbitDbt = (ConnGrbitDbt)context.ReadUInt16();
            var hj = context.ReadUInt16();
            this.bVerDbqueryEdit = context.ReadByte();
            this.bVerDbqueryRefreshed = context.ReadByte();
            this.bVerDbqueryRefreshableMin = context.ReadByte();
            context.ReadByte();
            context.ReadUInt16();
            this.coledb = context.ReadUInt16();

            this.cstFuture = context.ReadUInt16();
            this.wRefreshInterval = context.ReadUInt16();
            this.wHtmlFmt = context.ReadUInt16();
            this.cwParamFlags = context.ReadUInt16();
            this.rgPbt = new List<PBT>();
            for (int i = 0; i < this.cwParamFlags; i++ )
            {
                PBT pbt = new PBT();
                pbt.Read(context.Reader);
                this.rgPbt.Add(pbt);
            }
                this.rgbFutureBytes = context.ReadBytes(cstFuture);
        }

        internal override BiffRecordType RecordType
        {
            get { return BiffRecordType.DBQueryExt; }
        }

        internal override void WriteContent(BiffWriterWorkbookContext context)
        {
            throw new NotImplementedException();
        }
    }

    internal class PBT
    {
        public void Read(BinaryReader reader)
        {
            throw new NotImplementedException();
        }
    }
}